//
//  CZMainViewController.swift
//  crkWeibo
//
//  Created by 陈荣科 on 15/12/16.
//  Copyright © 2015年 crk. All rights reserved.
//https://api.weibo.com/oauth2/authorize?client_id=1255432106&redirect_uri=http://www.baidu.com/

import UIKit

class CZMainViewController: UITabBarController {

    
    override func loadView() {
        super.loadView()
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        //tabBarItem字体的颜色
//        self.tabBar.tintColor = UIColor.orangeColor()
        
        //自定义tabbar 
        let mainTabbar = CZMainTabBar()
        
        self.setValue(mainTabbar, forKey: "tabBar")
        
        //home控制器
        let homeContrller = CZHomeViewController()
        self.addChildViewContr(homeContrller, title: "首页", imageName: "tabbar_home")
        
        //message控制器
        let msgController = CZMessageViewController()
        self.addChildViewContr(msgController, title: "消息", imageName: "tabbar_message_center")
        
        
        //Discovery控制器
        let discvController = CZDiscoveryViewController()
        self.addChildViewContr(discvController, title: "发现", imageName: "tabbar_discover")
        
        //profile控制器
        let profController = CZProfileViewController()
        self.addChildViewContr(profController, title: "我", imageName: "tabbar_profile")
        
    }
    func addChildViewContr(controller: UIViewController, title: String,imageName: String) {
    
        self.addChildViewController(UINavigationController(rootViewController: controller))
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imageName)
        
        
        //设置高亮图片
        let highlightImageName = imageName + "_highlighted"
        controller.tabBarItem.selectedImage = UIImage(named: highlightImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置文字颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
    
    }


}
